home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpcsrc.lha / fpc / compiler / tree.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  38KB  |  1,276 lines

  1. {
  2.     $Id: tree.pas,v 1.1.1.1 1998/03/25 11:18:13 root Exp $
  3.     Copyright (c) 1993-98 by Florian Klaempfl
  4.  
  5.     This units exports some routines to manage the parse tree
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  ****************************************************************************
  22. }
  23.  
  24. {$ifdef tp}
  25.   {E+,N+}
  26. {$endif}
  27. unit tree;
  28.  
  29.   interface
  30.  
  31.     uses
  32.        objects,globals,symtable,cobjects,verbose,aasm,files
  33. {$ifdef i386}
  34.        ,i386
  35. {$endif}
  36. {$ifdef m68k}
  37.        ,m68k
  38. {$endif}
  39. {$ifdef alpha}
  40.        ,alpha
  41. {$endif}
  42.        ;
  43.  
  44.     type
  45.        tconstset = array[0..31] of byte;
  46.  
  47.        pconstset = ^tconstset;
  48.  
  49.        ttreetyp = (addn,            {Represents the + operator.}
  50.                    muln,            {Represents the * operator.}
  51.                    subn,            {Represents the - operator.}
  52.                    divn,            {Represents the div operator.}
  53.                    symdifn,         {Represents the >< operator.}
  54.                    modn,            {Represents the mod operator.}
  55.                    assignn,         {Represents an assignment.}
  56.                    loadn,           {Represents the use of a variabele.}
  57.                    rangen,          {Represents a range (i.e. 0..9).}
  58.                    ltn,             {Represents the < operator.}
  59.                    lten,            {Represents the <= operator.}
  60.                    gtn,             {Represents the > operator.}
  61.                    gten,            {Represents the >= operator.}
  62.                    equaln,          {Represents the = operator.}
  63.                    unequaln,        {Represents the <> operator.}
  64.                    inn,             {Represents the in operator.}
  65.                    orn,             {Represents the or operator.}
  66.                    xorn,            {Represents the xor operator.}
  67.                    shrn,            {Represents the shr operator.}
  68.                    shln,            {Represents the shl operator.}
  69.                    slashn,          {Represents the / operator.}
  70.                    andn,            {Represents the and operator.}
  71.                    subscriptn,      {??? Field in a record/object?}
  72.                    derefn,          {Dereferences a pointer.}
  73.                    addrn,           {Represents the @ operator.}
  74.                    doubleaddrn,     {Represents the @@ operator.}
  75.                    ordconstn,       {Represents an ordinal value.}
  76.                    typeconvn,       {Represents type-conversion/typecast.}
  77.                    calln,           {Represents a call node.}
  78.                    callparan,       {Represents a parameter.}
  79.                    realconstn,      {Represents a real value.}
  80.                    fixconstn,       {Represents a fixed value.}
  81.                    umminusn,        {Represents a sign change (i.e. -2).}
  82.                    asmn,            {Represents an assembler node }
  83.                    vecn,            {Represents array indexing.}
  84.                    stringconstn,    {Represents a string constant.}
  85.                    funcretn,        {Represents the function result var.}
  86.                    selfn,           {Represents the self parameter.}
  87.                    notn,            {Represents the not operator.}
  88.                    inlinen,         {Internal procedures (i.e. writeln).}
  89.                    niln,            {Represents the nil pointer.}
  90.                    errorn,          {This part of the tree could not be
  91.                                      parsed because of a compiler error.}
  92.                    typen,           {A type name. Used for i.e. typeof(obj).}
  93.                    hnewn,           {The new operation, constructor call.}
  94.                    hdisposen,       {The dispose operation with destructor call.}
  95.                    newn,            {The new operation, constructor call.}
  96.                    simpledisposen,  {The dispose operation.}
  97.                    setelen,         {A set element (i.e. [a,b]).}
  98.                    setconstrn,      {A set constant (i.e. [1,2]).}
  99.                    blockn,          {A block of statements.}
  100.                    anwein,          {A linear list of nodes.}
  101.                    loopn,           { used in genloopnode, must be converted }
  102.                    ifn,             {An if statement.}
  103.                    breakn,          {A break statement.}
  104.                    continuen,       {A continue statement.}
  105.                    repeatn,         {A repeat until block.}
  106.                    whilen,          {A while do statement.}
  107.                    forn,            {A for loop.}
  108.                    exitn,           {An exit statement.}
  109.                    withn,           {A with statement.}
  110.                    casen,           {A case statement.}
  111.                    labeln,          {A label.}
  112.                    goton,           {A goto statement.}
  113.                    simplenewn,      {The new operation.}
  114.                    tryexceptn,      {A try except block.}
  115.                    raisen,          {A raise statement.}
  116.                    switchesn,       {??? Currently unused...}
  117.                    tryfinallyn,     {A try finally statement.}
  118.                    isn,             {Represents the is operator.}
  119.                    asn,             {Represents the as typecast.}
  120.                    caretn,          {Represents the ^ operator.}
  121.                    failn,           {Represents the fail statement.}
  122.                    { added for optimizations where we cannot suppress }
  123.                    nothingn,
  124.                    loadvmtn);       {???.}
  125.  
  126.        tconverttype = (tc_equal,tc_not_possible,tc_u8bit_2_s32bit,
  127.                       tc_only_rangechecks32bit,tc_s8bit_2_s32bit,
  128.                       tc_u16bit_2_s32bit,tc_s16bit_2_s32bit,
  129.                       tc_s32bit_2_s16bit,tc_s32bit_2_u8bit,
  130.                       tc_s32bit_2_u16bit,tc_string_to_string,
  131.                       tc_cstring_charpointer,tc_string_chararray,
  132.                       tc_array_to_pointer,tc_pointer_to_array,
  133.                       tc_char_to_string,tc_u8bit_2_s16bit,
  134.                       tc_u8bit_2_u16bit,tc_s8bit_2_s16bit,
  135.                       tc_s16bit_2_s8bit,tc_s16bit_2_u8bit,
  136.                       tc_u16bit_2_s8bit,tc_u16bit_2_u8bit,
  137.                       tc_s8bit_2_u16bit,tc_s32bit_2_s8bit,
  138.                       tc_s32bit_2_u32bit,tc_s16bit_2_u32bit,
  139.                       tc_s8bit_2_u32bit,tc_u16bit_2_u32bit,
  140.                       tc_u8bit_2_u32bit,tc_u32bit_2_s32bit,
  141.                       tc_int_2_real,tc_real_2_fix,
  142.                       tc_fix_2_real,tc_int_2_fix,tc_real_2_real,
  143.                       tc_chararray_2_string,tc_bool_2_u8bit,
  144.                       tc_proc2procvar,
  145.                       tc_cchar_charpointer);
  146.  
  147.        { allows to determine which elementes are to be replaced }
  148.        tdisposetyp = (dt_nothing,dt_leftright,dt_left,
  149.                       dt_mbleft,dt_string,dt_typeconv,dt_inlinen,
  150.                       dt_mbleft_and_method,dt_constset,dt_loop,dt_case,
  151.                       dt_with);
  152.  
  153.       { different assignment types }
  154.  
  155.       tassigntyp = (at_normal,at_plus,at_minus,at_star,at_slash);
  156.  
  157.       pcaserecord = ^tcaserecord;
  158.  
  159.       tcaserecord = record
  160.  
  161.           { range }
  162.           _low,_high : longint;
  163.  
  164.           { only used by gentreejmp }
  165.           _at : plabel;
  166.  
  167.           { label of instruction }
  168.           statement : plabel;
  169.  
  170.           { left and right tree node }
  171.           less,greater : pcaserecord;
  172.        end;
  173.  
  174.        ptree = ^ttree;
  175.  
  176.        ttree = record
  177.           error : boolean;
  178.